package com.itheima.listener.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DlxConfig {

    /****
     * 声明普通的交换机
     */
    @Bean
    public DirectExchange simpleDirect() {
        return new DirectExchange("simple.direct");
    }

    /****
     * 声明普通队列
     */
    @Bean
    public Queue simpleQueue() {
        return QueueBuilder.durable("simple.queue")
                .ttl(5000)
                .deadLetterExchange("dlx.direct")
                .deadLetterRoutingKey("dlx")
                .build();
    }
    /****
     * 创建死信交换机
     */
    @Bean
    public DirectExchange dlxDirect() {
        return new DirectExchange("dlx.direct");
    }
    /****
     * 创建死信队列
     */
  @Bean
  public Queue dlxQueue() {
      return  QueueBuilder.durable("dlx.queue")
              .build();
  }

    /****
     * 死信交换机绑定死信队列
     */
    @Bean
    public Binding dlxQueueBinding(DirectExchange dlxDirect,Queue dlxQueue){
        return BindingBuilder.bind(dlxQueue).to(dlxDirect).with("dlx");
    }

}
